<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>用户基本信息</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css"
	media="all">
<link rel="stylesheet" href="../css/public.css" media="all">
<style>
.layui-form-item .layui-input-company {
	width: auto;
	padding-right: 10px;
	line-height: 38px;
}
</style>
</head>
<body>
	<form class="layui-form" action="">
		<div class="layuimini-container">
			<div class="layuimini-main">

				<div class="layui-form layuimini-form">
					<div class="layui-form-item">
						<label class="layui-form-label">用户ID:</label>
							<div class="layui-input-block">
							<input type="text" id="userid" name="userid" class="layui-input"
								lay-verify="required" lay-reqtext="用户ID获取失败" hidden="hidden"
								readonly="true">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label required">账号名称：</label>
						<div class="layui-input-block">
							<input type="text" id="username" name="username" required=""
								lay-verify="required|username" lay-reqtext="用户名不能为空"
								placeholder="请输入用户名" autocomplete="off" class="layui-input">
							<tip>请填写自己账号的名称！</tip>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label required ">手机号：</label>
						<div class="layui-input-block">
							<input type="text" id="ProtectTel" name="ProtectTel" required=""
								lay-verify="required|phone|number" autocomplete="off"
								placeholder="请输入手机号" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">邮箱：</label>
						<div class="layui-input-block">
							<input type="text" id="ProtectEmail" name="ProtectEmail"
								required="" lay-verify="required|email" autocomplete="off"
								placeholder="请输入电子邮箱" class="layui-input">
						</div>
					</div>
					<!-- <div class="layui-form-item layui-form-text">
						<label class="layui-form-label">备注信息：</label>
						<div class="layui-input-block">
							<textarea name="remark" id="remark" class="layui-textarea"
								placeholder="请输入备注信息"></textarea>
						</div>
					</div> -->

					<div class="layui-form-item">
						<div class="layui-input-block">
							<button class="layui-btn layui-btn-normal" lay-submit=""
								lay-filter="usersEditBtu">确认保存</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</form>
	<script type="text/javascript" src="layui/layui.js"></script>
	<script src="js/Global.js" type="text/javascript" charset="utf-8"></script>
	<script>
		layui.use([ 'form', 'layedit' ], function() {
			var form = layui.form, layer = layui.layer, $ = layui.$;
			var layedit = layui.layedit;
			layedit.build('content', {
				height : 180
			//设置编辑器高度
			});
			form.verify({
				username : function(value, item) { //value：表单的值、item：表单的DOM对象
					if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$")
							.test(value)) {
						return '用户名不能有特殊字符';
					}
					if (/(^\_)|(\__)|(\_+$)/.test(value)) {
						return '用户名首尾不能出现下划线\'_\'';
					}
					if (/^\d+\d+\d$/.test(value)) {
						return '用户名不能全为数字';
					}

					//如果不想自动弹出默认提示框，可以直接返回 true，这时你可以通过其他任意方式提示（v2.5.7 新增）
					if (value === 'name' || value === 'username'
							|| value === 'sb') {
						return '用户名不能为敏感词';
					}
				}

				//我们既支持上述函数式的方式，也支持下述数组的形式
				//数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
				,
				pass : [ /^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格' ]
			});
			$("#username").val(globalData.getUserName());
			$("#userid").val(globalData.getUid());
			$("#ProtectTel").val(globalData.ProtectTel());
			$("#ProtectEmail").val(globalData.ProtectEmail());
			//监听提交
			form.on('submit(Btu)', function(data) {
				var d = data.field; //表单中的数据，定义一个对象来接收
				d.method = "update";
				//通过ajax向数据库提交数据了
				console.log(d); //提交之前的一个数据验证、通过打印的方式先手动的去判断一下这个数据
				var url = globalData.server+'public/updateUsers';
				$.post(url, d, function(data) {
					if(data.count > 0) {
						var iframeIndex = parent.layer.getFrameIndex(window.name);
						parent.layer.close(iframeIndex);
					}
				}, "json");
				return false;
			});
		});
	</script>
</body>
</html>